package org.oa.ai.model;

import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import jakarta.annotation.PostConstruct;
import org.oa.ai.model.impl.DeepseekR1Model;
import org.oa.ai.model.impl.Qwen2_5Model;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ModelService {
    // 使用Map保存模型实例（可替换为Spring Bean工厂）
    private final Map<String, ModelProcessor> modelMap = new HashMap<>();

    @PostConstruct
    public void init() {
        modelMap.put("deepseekR1", new DeepseekR1Model());
        modelMap.put("qwen2.5", new Qwen2_5Model());
    }

    public String chatMessage(String modelName, String message) {
        ModelProcessor processor = modelMap.get(modelName);
        if (processor == null) {
            throw new IllegalArgumentException("未知模型：" + modelName);
        }
        return processor.chatMessage(message);
    }

    public StreamingChatLanguageModel chatMessageStream(String modelName) {
        ModelProcessor processor = modelMap.get(modelName);
        if (processor == null) {
            throw new IllegalArgumentException("未知模型：" + modelName);
        }
        return processor.chatMessageStream();
    }

}
